package com.bauer.framework.autumn.annotation.paser;

import com.bauer.framework.autumn.annotation.Bean;
import com.bauer.framework.autumn.utils.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author ：rui.wei
 * @Date ：Created in 17:00 2018/8/2
 * @Description：
 */
public class AnnotationPaser {

    private Map<String ,Annotation> annotatedTypeMap = new HashMap<>();

    private static Set<Class<? extends Annotation>> excludedAnnotion = new HashSet<>();

    public AnnotationPaser(Class ca){
        loadAnnotations(ca);
    }

    public boolean hasAnnotion(String annotionName){
        return annotatedTypeMap.containsKey(annotionName);
    }


    private void loadAnnotations(Class loadClass){

        Annotation[] annotatedTypes = loadClass.getAnnotations();
        for (Annotation annotation : annotatedTypes) {

            if (AnnotationUtils.isJavaAnnotation(annotation.annotationType().getName())) {
                continue;
            }

            if (annotation instanceof Bean) {
                annotatedTypeMap.put(annotation.annotationType().getName(),annotation);
            }else {
                loadAnnotations(annotation.annotationType());
            }
        }
    }
}
